﻿/*----------------------------------------------------------------
           // Copyright (C) 2008 安华顺通(北京)科技有限公司
           // 版权所有。 
           //
           // 文件名： QueryFieldType.cs
           // 文件功能描述：Query字段的字段类型。
           //
           // 
           // 创建标识：丁余良 20080927
           //
           // 修改标识
           // 修改描述：
           //
           // 修改标识：
           // 修改描述：
----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;


namespace RuleCode.Common
{  
    /// <summary>
    /// 
    /// </summary>
    public class QueryFieldType : Object,IBaseInterface 
    {
        private string label;
        /// <summary>
        /// 多语言显示 
        /// </summary>
        public string ZLabel
        {
            get { return this.label; }
            set { this.label = value; }
        }

        public virtual void SetValue(object value) { }
        public virtual object ObjectValue { get; set; }
        public virtual string StringValue { get; set; }
        public virtual System.Type ValueType { get; set; }

        
    }

    /// <summary>
    /// QInt 类的数据类型为int
    /// </summary>
    public class QInt : QueryFieldType
    {
        private  int value;
        
        public static readonly QInt Null = new QInt();

        public QInt() {  }
        public QInt(int val) { this.value = val;  }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性
        
        public int Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(int); } }
        public override object ObjectValue { get { return this.value; } set { this.value = (int)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToInt32(value); }
        }
        #endregion

        #region QInt和int之间的显式转换
        public static implicit operator QInt(int x) { return new QInt(x); }
        public static explicit operator int(QInt x) {  return x.Value; }
        #endregion

        #region 运算符
        public static QInt operator +(QInt x) { return x; }
        public static QInt operator -(QInt x) { return new QInt(-x.value) ; }

        public static QInt operator +(QInt x, QInt y) { return  new QInt(x.value + y.value) ; }
        public static QInt operator -(QInt x, QInt y) { return  new QInt(x.value - y.value) ; }
        public static QInt operator *(QInt x, QInt y) { return  new QInt(x.value * y.value) ; }
        public static QInt operator /(QInt x, QInt y) { return  new QInt(x.value / y.value) ; }
        public static QInt operator %(QInt x, QInt y) { return  new QInt(x.value % y.value) ; }


        //QInt.Null可以和其他QInt 对象比较操作==,!=；
        public static bool operator ==(QInt x, QInt y) { return  x.value == y.value ; }
        public static bool operator !=(QInt x, QInt y) { return  x.value != y.value ; }
        public static bool operator >(QInt x, QInt y) { return  x.value > y.value ; }
        public static bool operator <(QInt x, QInt y) { return  x.value < y.value ; }
        public static bool operator >=(QInt x, QInt y) { return  x.value >= y.value; }
        public static bool operator <=(QInt x, QInt y) { return  x.value <= y.value ; }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (int)value;

        }

    }


    /// <summary>
    /// QInt64 数据类型
    /// </summary>
    public class QInt64 : QueryFieldType
    {
        private  Int64 value;
        
        public static readonly QInt64 Null = new QInt64();

        public QInt64() {  }
        public QInt64(Int64 value) { this.value = value;  }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性
        
        public Int64 Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region QInt64和Int64之间的显式转换
        public static implicit operator QInt64(Int64 x) { return new QInt64(x); }
        public static explicit operator Int64(QInt64 x) {  return x.Value; }
        #endregion

        #region 运算符
        public static QInt64 operator +(QInt64 x) { return x; }
        public static QInt64 operator -(QInt64 x) { return new QInt64(-x.value) ; }

        public static QInt64 operator +(QInt64 x, QInt64 y) { return  new QInt64(x.value + y.value) ; }
        public static QInt64 operator -(QInt64 x, QInt64 y) { return  new QInt64(x.value - y.value) ; }
        public static QInt64 operator *(QInt64 x, QInt64 y) { return  new QInt64(x.value * y.value) ; }
        public static QInt64 operator /(QInt64 x, QInt64 y) { return  new QInt64(x.value / y.value) ; }
        public static QInt64 operator %(QInt64 x, QInt64 y) { return  new QInt64(x.value % y.value) ; }


        //QInt.Null可以和其他QInt 对象比较操作==,!=；
        public static bool operator ==(QInt64 x, QInt64 y) { return  x.value == y.value ; }
        public static bool operator !=(QInt64 x, QInt64 y) { return  x.value != y.value ; }
        public static bool operator >(QInt64 x, QInt64 y) { return  x.value > y.value ; }
        public static bool operator <(QInt64 x, QInt64 y) { return  x.value < y.value ; }
        public static bool operator >=(QInt64 x, QInt64 y) { return  x.value >= y.value ; }
        public static bool operator <=(QInt64 x, QInt64 y) { return  x.value <= y.value ; }
        #endregion


        #region
        public override System.Type ValueType { get { return typeof(Int64); } }
        public override object ObjectValue { get { return this.value; } set { this.value = (Int64)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToInt64(value); }
        }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (Int64)value;
        }

    }

    /// <summary>
    /// QString 数据类型
    /// </summary>
    public class QString : QueryFieldType
    {
        public static readonly QString Null = new QString();
        private string value;
        

        public QString() {  }
        public QString(string value) { this.value = value;  }

        #region 属性
        
        public string Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        public int Length { get { return this.value.Length; } }
        #endregion

        #region 方法
        public static implicit operator QString(string x) { return new QString(x); }
        public static explicit operator string(QString x) { return x.Value; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        public static QString operator +(QString x, QString y) { return  new QString(x.value + y.value) ; }
        public static bool operator ==(QString x, QString y) { return  x.value == y.value ; }
        public static bool operator !=(QString x, QString y) { return  x.value != y.value ; }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(string); } }
        /// <summary>
        /// string 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (string)value; } }
        public override string StringValue
        {
            get { return this.value; }
            set { this.value = value; }
        }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (string)value;
        }

    }

    /// <summary>
    ///QFloat数据类型 
    /// </summary>
    public class QFloat : QueryFieldType
    {
        private  float value;
        
        public static readonly QFloat Null = new QFloat();

        public QFloat() {  }
        public QFloat(float val) { this.value = val;  }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性
        
        public float Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region QFloat和float之间的显式转换
        public static implicit operator QFloat(float x) { return new QFloat(x); }
        public static explicit operator float(QFloat x) { return x.Value; }
        #endregion

        #region 运算符
        public static QFloat operator +(QFloat x) { return x; }
        public static QFloat operator -(QFloat x) { return new QFloat(-x.value) ; }

        public static QFloat operator +(QFloat x, QFloat y) { return  new QFloat(x.value + y.value) ; }
        public static QFloat operator -(QFloat x, QFloat y) { return  new QFloat(x.value - y.value) ; }
        public static QFloat operator *(QFloat x, QFloat y) { return  new QFloat(x.value * y.value) ; }


        //QInt.Null可以和其他QInt 对象比较操作==,!=；
        public static bool operator ==(QFloat x, QFloat y) { return  x.value == y.value ; }
        public static bool operator !=(QFloat x, QFloat y) { return  x.value != y.value ; }
        public static bool operator >(QFloat x, QFloat y) { return  x.value > y.value ; }
        public static bool operator <(QFloat x, QFloat y) { return  x.value < y.value ; }
        public static bool operator >=(QFloat x, QFloat y) { return  x.value >= y.value ; }
        public static bool operator <=(QFloat x, QFloat y) { return  x.value <= y.value ; }
        #endregion


        #region 接口实现
        public override System.Type ValueType { get { return typeof(float); } }
        /// <summary>
        /// float 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (float)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }

            set { this.value = Convert.ToSingle(value); }
        }
        #endregion

        public override void SetValue(object value)
        {
            System.Type type = value.GetType();
            this.value = (float)value;
        }

    }


    /// <summary>
    ///QDouble数据类型 
    /// </summary>
    public class QDouble : QueryFieldType
    {
        private  double value;
        
        public static readonly QDouble Null = new QDouble();

        public QDouble() {  }
        public QDouble(double val) { this.value = val;  }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性
        
        public double Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region QFloat和float之间的显式转换
        public static implicit operator QDouble(double x) { return new QDouble(x); }
        public static explicit operator double(QDouble x) { return x.Value; }
        #endregion

        #region 运算符
        public static QDouble operator +(QDouble x) { return x; }
        public static QDouble operator -(QDouble x) { return new QDouble(-x.value) ; }

        public static QDouble operator +(QDouble x, QDouble y) { return  new QDouble(x.value + y.value) ; }
        public static QDouble operator -(QDouble x, QDouble y) { return  new QDouble(x.value - y.value) ; }
        public static QDouble operator *(QDouble x, QDouble y) { return  new QDouble(x.value * y.value) ; }


        //QInt.Null可以和其他QInt 对象比较操作==,!=；
        public static bool operator ==(QDouble x, QDouble y) { return  x.value == y.value ; }
        public static bool operator !=(QDouble x, QDouble y) { return  x.value != y.value ; }
        public static bool operator >(QDouble x, QDouble y) { return  x.value > y.value ; }
        public static bool operator <(QDouble x, QDouble y) { return  x.value < y.value ; }
        public static bool operator >=(QDouble x, QDouble y) { return  x.value >= y.value ; }
        public static bool operator <=(QDouble x, QDouble y) { return  x.value <= y.value ; }
        #endregion


        #region 接口实现
        public override System.Type ValueType { get { return typeof(double); } }
        /// <summary>
        /// Double 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (double)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToDouble(value); }

        }
        #endregion

        public override void SetValue(object value)
        {
            System.Type type = value.GetType();
            this.value = (double)value;
        }

    }
    


    /// <summary>
    /// QDate类 日期
    /// </summary>
    public class QDate : QueryFieldType
    {

        private static int minYear = 1;
        private static int maxYear = 2500;
        private int year;
        private int month;
        private int day;
        

        #region 构造函数
        public QDate() {  }
        public QDate(int y, int m, int d)
        {
            
            if (ValidateDate(y, m, d))
            {
                this.year = y;
                this.month = m;
                this.day = d;
            }
        }
        public QDate(DateTime dTime) { this.day = dTime.Day; this.month = dTime.Month; this.year = dTime.Year; }
        #endregion

        #region 属性
        //public System.Type ControlType { get { return ((new DateTimePicker()).GetType()); } }
        public int DayOfYear { get { return (new DateTime(this.Year, this.Month, this.Day)).DayOfYear; } }
        
        public int Year { get { return this.year; } }
        public int Month { get { return this.month; } }
        public int Day { get { return this.day; } }
        public bool IsLeapyear { get { return (((this.Year % 4 == 0) && (this.Year % 100 != 0)) || ((this.Year % 100 == 0) && (this.Year % 400 == 0))); } }
        public DateTime Value { get { return (DateTime)(this); } set { this.ObjectValue = value; } }

        public string Date
        {
            get
            {
                string date = this.Year.ToString() + "-";
                if (this.Month < 10)
                    date = date + "0";
                date = date + this.Month.ToString() + "-";
                if (this.day < 10)
                    date = date + "0";
                date = date + this.Day.ToString();
                return date;
            }
            set
            {
                DateTime dTime = Convert.ToDateTime(value);
                this.year = dTime.Year;
                this.month = dTime.Month;
                this.day = dTime.Day;
            }
        }
        #endregion


        #region 验证函数
        //判断输入的年月日是否符合逻辑！
        public bool ValidateDate(int y, int m, int d)
        {
            bool result = (y >= minYear) && (y <= maxYear);
            result = result && (m >= 1) && (m <= 12);
            result = result && (d > 0);
            List<int> Days31 = new List<int>(new int[] { 1, 3, 5, 7, 8, 10, 12 });
            List<int> Days30 = new List<int>(new int[] { 4, 6, 9, 11 });

            if (Days31.Contains(m))
                return result && (d < 32);
            else if (Days30.Contains(m))
                return result && (d < 31);
            else if (m == 2)
                if (((y % 4 == 0) && (y % 100 != 0)) || ((y % 100 == 0) && (y % 400 == 0)))
                    return result && (d < 30);
                else
                    return result && (d < 29);
            if (!result)
                throw new InvalidTimeZoneException("你输入的日期超出范围！！");
            else
                return result;
        }
        #endregion

        #region 重载
        public override string ToString() { return this.StringValue; }
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        #endregion

        #region 操作符以及转换
        public static implicit operator QDate(DateTime dTime) { return new QDate(dTime); }
        public static explicit operator DateTime(QDate tDate) { return new DateTime(tDate.Year, tDate.Month, tDate.Day); }

        public static bool operator ==(QDate x, QDate y) { return  (x.Day == y.Day && x.Month == y.Month && x.Year == y.Year) ; }
        public static bool operator !=(QDate x, QDate y) { return  x.Day != y.Day || x.Month != y.Month || x.Year != y.Year ; }
        public static bool operator >(QDate x, QDate y) { return  (x.Year > y.Year) || (x.Year == y.Year && x.Month > y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day > y.Day) ; }
        public static bool operator <(QDate x, QDate y) { return  (x.Year < y.Year) || (x.Year == y.Year && x.Month < y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day < y.Day) ; }
        public static bool operator >=(QDate x, QDate y) { return  (x.Year >= y.Year) || (x.Year == y.Year && x.Month >= y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day >= y.Day) ; }
        public static bool operator <=(QDate x, QDate y) { return  (x.Year <= y.Year) || (x.Year == y.Year && x.Month <= y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day <= y.Day) ; }

        public static int operator -(QDate x, QDate y) {  return x.SubStract(y); }
        #endregion

        #region  DateTime属性
        public QDate AddDays(int days)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddDays(days);
            return (QDate)(dTime);
        }
        public QDate AddMonths(int months)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddMonths(months);
            return (QDate)(dTime);
        }
        public QDate AddYears(int years)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddYears(years);
            return (QDate)(dTime);
        }
        public int SubStract(QDate tDate)
        {
            TimeSpan tSpan = new TimeSpan();
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            tSpan = dTime.Subtract((DateTime)(tDate));
            return (int)(tSpan.TotalDays);
        }
        public QDate SubStract(int days)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            return (QDate)(dTime.Subtract(new TimeSpan(days, 0, 0, 0)));
        }
        #endregion


        #region
        public override System.Type ValueType { get { return typeof(DateTime); } }
        /// <summary>
        /// DateTime 类型 (QDate)
        /// </summary>
        public override object ObjectValue
        {
            get { return (DateTime)this; }
            set
            {
                
                this.year = ((DateTime)value).Year;
                this.month = ((DateTime)value).Month;
                this.day = ((DateTime)value).Day;
            }
        }
        public override string StringValue
        {
            get { return this.Date; }
            set { this.Date = value; }
        }
        #endregion

        public override void SetValue(object value)
        {
            this.year = ((DateTime)value).Year;
            this.month = ((DateTime)value).Month;
            this.day = ((DateTime)value).Day;
        }

    }

    /// <summary>
    /// QTime类 时间 24小时制
    /// </summary>
    public class QTime : QueryFieldType
    {


        private int hour;
        private int minute;
        private int second;
        
        private int time;

        #region 构造函数
        public QTime() {  }
        public QTime(int x)
        {
            
            if (x >= 0)
            {
                int y = x % (60 * 60 * 24);
                this.hour = y / (60 * 60);
                this.minute = (y % (60 * 60)) / 60;
                this.second = (y % (60 * 60)) % 60;
            }
            else
            {
                throw new ArgumentException("输入参数太大或太小！");
            }

        }
        public QTime(int h, int m, int s)
        {
            
            if (ValidateTime(h, m, s))
            {
                this.hour = h; this.minute = m; this.second = s;
                time = h * 60 * 60 + m * 60 + s;
            }
        }
        public QTime(string timeString)
        {
            this.Time = timeString;
        }
        #endregion

        #region 验证函数
        public bool ValidateTime(int h, int m, int s)
        {
            bool result = (h >= 0 && h < 24) && (m >= 0 && m < 60) && (s >= 0 && s < 60);
            if (!result)
                throw new InvalidTimeZoneException("你输入的时间超出范围！！");
            else
                return result;
        }
        #endregion

        #region 属性
        
        public int Hour { get { return this.hour; } }
        public int Minute { get { return this.minute; } }
        public int Second { get { return this.second; } }
        //public System.Type ControlType { get { return ((new DateTimePicker()).GetType()); } }
        public int Value { get { return this.TimeOffset; } set { this.TimeOffset = value; } }
        public string Time
        {
            get
            {
                string time0 = "";
                if (this.hour < 10)
                    time0 += "0";
                time0 += this.hour.ToString() + ":";
                if (this.minute < 10)
                    time0 += "0";
                time0 += this.minute.ToString() + ":";
                if (this.second < 10)
                    time0 += "0";
                time0 += this.second.ToString();
                return time0;
            }
            set
            {

                string pattern = "[0-1][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9]";
                if (Regex.IsMatch(value, pattern))
                {
                    string timestring = value;
                    string[] time0 = timestring.Split(new char[] { ':' });
                    string hourString = time0[0];
                    string minuterString = time0[1];
                    string secondString = time0[2];
                    if (hourString == "00")
                        this.hour = 0;
                    else
                        this.hour = Convert.ToInt32(hourString.TrimStart(new char[] { '0' }));

                    if (minuterString == "00")
                        this.minute = 0;
                    else
                        this.minute = Convert.ToInt32(minuterString.TrimStart(new char[] { '0' }));

                    if (secondString == "00")
                        this.second = 0;
                    else
                        this.second = Convert.ToInt32(secondString.TrimStart(new char[] { '0' }));
                    this.time = this.Hour * 60 * 60 + this.Minute * 60 + this.second;

                }
                else
                {
                    throw new InvalidCastException("格式不正确，不能转换");
                }
            }
        }

        public int TimeOffset
        {
            get { return this.time; }
            set
            {
                int x = value;
                if (x >= 0)
                {
                    x = x % (60 * 60 * 24);
                    this.hour = x / (60 * 60);
                    this.minute = (x % (60 * 60)) / 60;
                    this.second = (x % (60 * 60)) % 60;
                }
                else
                {
                    throw new ArgumentException("输入参数太大或太小！");
                }

            }
        }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region 操作符和类型转换
        public static implicit operator QTime(int x) { return new QTime(x); }
        public static explicit operator int(QTime tTime) {  return tTime.TimeOffset; }//

        public static bool operator ==(QTime x, QTime y) { return  x.TimeOffset == y.TimeOffset ; }
        public static bool operator !=(QTime x, QTime y) { return  x.TimeOffset != y.TimeOffset ; }
        public static bool operator >(QTime x, QTime y) { return  x.TimeOffset > y.TimeOffset ; }
        public static bool operator <(QTime x, QTime y) { return  x.TimeOffset < y.TimeOffset ; }
        public static bool operator >=(QTime x, QTime y) { return  x.TimeOffset >= y.TimeOffset ; }
        public static bool operator <=(QTime x, QTime y) { return  x.TimeOffset <= y.TimeOffset ; }

        public static QTime operator -(QTime x, QTime y) { return new QTime(x.TimeOffset - y.TimeOffset); }
        #endregion

        #region QTime 方法
        public QTime AddSeconds(int seconds)
        {
            this.TimeOffset += seconds;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        public QTime AddMinutes(int minutes)
        {
            this.TimeOffset += minutes * 60;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        public QTime AddHours(int hours)
        {
            this.TimeOffset += hours * 60 * 60;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(string); } }
        /// <summary>
        /// 用 int 类型的设置值
        /// </summary>
        public override object ObjectValue
        {
            get { return this.TimeOffset; }
            set
            {

                this.TimeOffset = (int)value;
            }
        }
        /// <summary>
        /// 格式：01:01:01
        /// </summary>
        public override string StringValue
        {
            get { return this.Time; }
            set { this.Time = value; }
        }
        #endregion


    }


    /// <summary>
    /// QGuid类
    /// </summary>
    public class QGuid : QueryFieldType
    {

        private Guid value;
        

        #region 构造函数
        public QGuid() {  }
        public QGuid(Guid value) { this.value = value;  }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region 属性
        
        public Guid Value { get { return this.value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region 操作符和类型转换
        public static implicit operator QGuid(Guid x) { return new QGuid(x); }
        public static explicit operator Guid(QGuid x) {  return x.value; }
        //
        public static bool operator ==(QGuid x, QGuid y) { return  x.value == y.value ; }
        public static bool operator !=(QGuid x, QGuid y) { return  x.value != y.value ; }
        #endregion

        #region 接口实现
        public override System.Type ValueType { get { return typeof(Guid); } }
        /// <summary>
        /// Guid类型 QGuid
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (Guid)value; } }
        public override string StringValue { get { return this.value.ToString(); } set { this.value = new Guid(value); } }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (Guid)value;
        }
    }

    /// <summary>
    /// QContainer类
    /// </summary>
    public class QContainer : QueryFieldType
    {
        public static readonly QContainer Null = new QContainer();
        private Container value;
        

        #region 构造函数
        public QContainer() {  }
        public QContainer(Container value) { this.value = value;  }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region  属性
        
        public Container Value { get { return this.value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region 操作符和类型转换
        public static implicit operator QContainer(Container x) { return new QContainer(x); }
        public static explicit operator Container(QContainer x) { return x.value; }
        //
        public static bool operator ==(QContainer x, QContainer y) { return  x.value == y.value; }
        public static bool operator !=(QContainer x, QContainer y) { return  x.value != y.value; }
        #endregion

        #region 接口实现
        /// <summary>
        /// Container 类型 QContainer
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (Container)value; } }
        public override string StringValue { get { return this.ValueString; } set { this.value = null; } }
        public override System.Type ValueType { get { return typeof(Container); } }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (Container)value;
        }
    }

    /// <summary>
    /// QPoint类
    /// </summary>
    public class QPoint : QueryFieldType
    {
        public static QPoint Null = new QPoint();
        private int px;
        private int py;
        

        #region 构造函数
        public QPoint() {  }
        public QPoint(int x, int y) { this.px = x; this.py = y;  }
        public QPoint(Point pt) { this.px = pt.X; this.py = pt.Y;  }
        public QPoint(string pt) { this.StringValue = pt; }
        #endregion

        #region 重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region 属性
        
        public int X { get { return this.px; } }
        public int Y { get { return this.py; } }
        public string ValueString { get { return "(" + this.X.ToString() + "," + this.Y + ")"; } }
        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region 操作符重载 和 转换
        public static implicit operator QPoint(Point x) { return new QPoint(x); }
        public static explicit operator Point(QPoint x) {  return new Point(x.px, x.py); }

        public static QPoint operator +(QPoint x) { return x; }
        public static QPoint operator -(QPoint x) { return new QPoint(-x.px, -x.py); }

        public static bool operator ==(QPoint x, QPoint y) { return  (x.px == y.px) && (x.py == y.py) ; }
        public static bool operator !=(QPoint x, QPoint y) { return  (x.px != y.px) && (x.py != y.py) ; }
        public static QPoint operator +(QPoint x, QPoint y) { return  x.OffSet(y) ; }
        public static QPoint operator -(QPoint x, QPoint y) { return  x.OffSet(-y) ; }
        #endregion

        #region 其他方法
        public QPoint OffSet(int x, int y) { return new QPoint(this.px + x, this.py + y); }
        public QPoint OffSet(QPoint tp) { return new QPoint(this.px + tp.px, this.py + tp.py); }
        public QPoint OffSet(Point pt) { return new QPoint(this.px + pt.X, this.py + pt.Y); }
        #endregion

        #region 接口实现
        /// <summary>
        /// Point 类型 QPoint
        /// </summary>
        public override object ObjectValue
        {
            get { return (Point)this; }
            set
            {
                this.px = ((Point)value).X;
                this.py = ((Point)value).Y;
            }
        }
        public override string StringValue
        {
            get { return this.ValueString; }
            set
            {
                string pattern = "\\+?[1-9][0-9]*,\\+?[1-9][0-9]*";
                if (Regex.IsMatch(value, pattern))
                {
                    string[] pxy = value.Split(new char[] { ',' });
                    this.px = Convert.ToInt32(pxy[0]);
                    this.py = Convert.ToInt32(pxy[1]);
                }
                else
                {
                    throw new InvalidCastException("格式不正确，不能转换");
                }
            }
        }
        public override System.Type ValueType { get { return typeof(string); } }
        #endregion

        public override void SetValue(object value)
        {
            this.px = ((Point)value).X;
            this.py = ((Point)value).Y;
        }
    }

}

